﻿/*********************************************************************
 *
 *                             NOTICE
 *               COPYRIGHT (c) 2012 Panoscopix Software, Inc.
 *                UNPUBLISHED - ALL RIGHTS RESERVED
 * 
 *      This program is confidential, proprietary, and a trade
 *   secret of Panoscopix Software, Inc. The receipt or possession of
 *     this program does not convey any rights to reproduce or
 *      disclose its contents, or to manufacture, use, or sell
 *       anything that it may describe, in whole or in part, 
 *   without the specific written consent of Panoscopix Software, Inc.
 *
 * A simple in-memory implementation of a File.
 * 
 *******************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FileSystem;
using FileSystem.Utility;

namespace FileSystem.Impl
{
	class FSLink : IFSLink
	{
		private NodeMetaData  metaData;
		private IFSDirectory   parent;
		private IFSNode linkedNode;

		public FSLink(INodeMetaDataVO metaData, IFSNode linkedNode)
		{
			this.metaData = metaData.copy();
			parent = null;
			this.linkedNode = linkedNode;
		}

		public IFSDirectory getParent() {
			return parent;
		}

		public void setParent(IFSDirectory parent) {
			this.parent = parent;
		}

		public String getID() {
			return metaData.id;
		}
	
		public String getName() {
			return metaData.name;
		}

		public String getFQName() {
			if (null == parent) {
				return "[ORPHAN]/" + getName();
			}
			return parent.getFQName() + getName();
		}

		public void rename(String newName) {
			metaData.name = newName;
		}
	
		public int getSize() {
			return this.linkedNode.getSize();
		}
	
		public String getCreationTimestamp() {
			return metaData.getCreationTimestamp();
		}
	
		public String getContents() {
			return this.linkedNode.getContents();
		}
				
		public String describe() {
			return "Link " + getName() + "(" + getID() + ":" + getParentID() +
				"), created = " + getCreationTimestamp() + ", size = " + getSize();
		}
	
		public String describe(IPrintContext context) {
			return context.getFormattedString(describe());
		}
	
		public int numNodes() {
			return this.linkedNode.numNodes();
		}
	
		public IFSNode getNode(int i) {
			return linkedNode.getNode(i);
		}

		public bool addNode(IFSNode node) {
			return this.linkedNode.addNode(node);
		}

		public IFSNode removeNode(String name) {
			return this.linkedNode.removeNode(name);
		}

		private String getParentID() {
			if (null == parent) return "null";
			return parent.getID();
		}

		#region IFSLink Members

		public IFSNode GetLinkedNode()
		{
            return this.linkedNode;
		}

		#endregion

		#region IFSNode Members


		public void Accept(INodeVisitor visitor)
		{
			visitor.VisitLink(this);
		}

		#endregion
	}
}
